﻿//------------------------------------------------------------------------------
// 文件名称(File Name)：MappingExtensions.cs
//	功能描述(Description)：Entity和ViewModel的AutoMapper配置文件
//	数据表(Tables)：
//	作者(Author)：北斗
//	日期(Create Date)：2013-11-28
//	修改记录(Revision History)：
//------------------------------------------------------------------------------

using AutoMapper;
using XiaoMan.ViewModel;
using XiaoMan.Model.Models;

namespace XiaoMan.Service
{
    public static class MappingExtensions
    {

        #region Sys_Users 用户表
        public static Sys_UsersViewModel ToModel(this Sys_Users entity)
        {
            Mapper.CreateMap<Sys_Users, Sys_UsersViewModel>()
                .ForMember(d => d.CreateTime, o => o.MapFrom(s => CommonHelper.GetDateStr(s.CreateTime, "yyyy-MM-dd hh:mm:ss")))//创建时间
                .ForMember(d => d.UserTypeStr, o => o.MapFrom(s => ((enmUserType)s.UserType).ToString()));//用户类型

            return Mapper.Map<Sys_Users, Sys_UsersViewModel>(entity);
        }

        /// <summary>
        /// 把ViewModel转回Entity
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static Sys_Users ToEntity(this Sys_UsersViewModel entity)
        {
            Mapper.CreateMap<Sys_UsersViewModel, Sys_Users>();

            return Mapper.Map<Sys_UsersViewModel, Sys_Users>(entity);
        }
        #endregion

        #region Sys_Disease 疾病表
        public static Sys_DiseaseViewModel ToModel(this Sys_Disease entity)
        {
            Mapper.CreateMap<Sys_Disease, Sys_DiseaseViewModel>()
                .ForMember(d => d.IsFollow, o => o.MapFrom(s => "0"));//用户类型

            return Mapper.Map<Sys_Disease, Sys_DiseaseViewModel>(entity);
        }

        /// <summary>
        /// 把ViewModel转回Entity
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static Sys_Disease ToEntity(this Sys_DiseaseViewModel entity)
        {
            Mapper.CreateMap<Sys_DiseaseViewModel, Sys_Disease>();

            return Mapper.Map<Sys_DiseaseViewModel, Sys_Disease>(entity);
        }
        #endregion

    }
}
